<template>
	<view class="father">
		<view id="confirmbox">
			<view class="money">提现金额</view>
			<view class="inputbox">
				<text class="inputtext">￥</text>
				<input type="text" class="inputs" value="" v-model="balance.rechargeMoney" placeholder="请输入金额" />
			</view>
			<view class="text">当前余额{{userData.balance}},<text class="alltext" @tap="allmoney">全部提现</text></view>
		</view>
		<paypass ref="yspay" @submit="submitpay"></paypass>
		<view class="confirm" @tap="confirm">提现</view>
	</view>
</template>

<script>
	import paypass from "@/components/ys-paypass/ys-paypass.vue";
	import {createNamespacedHelpers} from 'vuex'
	const {mapActions} = createNamespacedHelpers('bankcard')
	const {mapMutations:userMapMutations,mapActions:userMapActions,mapState:userMapstate} = createNamespacedHelpers('UserInfor')
	export default {
		components:{
		        paypass
		},
		onLoad(option) {
			const item = JSON.parse(option.item)
			console.log(item); 
			this.balance.id=item.id;
			this.balance.memberUsername=item.memberUsername;
		},
		data() {
			return {
				balance:{ ///银行卡信息
					id: '',///银行卡id
					memberUsername:"",//用户账号
					password: "", ///实名后的钱包密码
					rechargeMoney: '',///提现金额
				}
			}
		},
		computed:{
			...userMapstate(['userData','userPass'])
		},
		methods: {
			...mapActions(['addbalance','WithdrawalCard']),
			...userMapActions(['getUser']),

			async submitpay(ex){ ////密码输入完成拿到的结果
			    // console.log('支付密码为：'+ex.value);
				this.balance.password=ex.value ///输完密码赋值
				const data = await this.WithdrawalCard(this.balance) ///输完密码调用传参
				console.log(data);
				if(data.code==607){
					uni.showToast({
						icon:'none',
					    title: '密码错误!',
					    duration: 2000
					});
				}else if(data.code==200){
					const userdata =await this.getUser({
						username:this.userData.username,
						password:this.userPass
					})
				if(userdata.code==200){
					uni.showToast({
						 title: '提现成功!',
						 duration: 2000
					},uni.navigateBack({
						 url:'/pages/bankCardRecharge/Withdrawal/Withdrawal'
					}))
				}
			}
		},
			//提现
			confirm(){
				 this.$refs.yspay.show();
			},
			//全部提现按钮
			allmoney(){
				this.balance.rechargeMoney=this.userData.balance
			}
		}
	}
</script>

<style>
	#confirmbox {
		width: 100%;
		height: auto;
	}
	.inputbox{
		display: flex;
		clear: both;
	}
	.inputtext{
		float: left;
		margin-top: 25rpx;
		margin-left: 10rpx;
	}
	.inputs{
		width: 95%;
	/* 	border: 1px solid red; */
		height: 88rpx;
		border-bottom: 1rpx solid #EEEEEE;
		margin: 0rpx auto 20rpx;
	}
	.alltext{
		color: #007AFF;
		margin-left: 10rpx;
	}
	.money {
		margin-top: 20rpx;
		padding-left: 20rpx;
		/* border: 1px solid red; */
		font-size: 25rpx;
		color: rgba(0,0,0,0.5);
		margin-bottom: 20rpx;
	}
	.text{
		/* border: 1px solid red; */
		padding-left: 20rpx;
		font-size: 28rpx;
		color: rgba(0,0,0,0.8);
	}
	.father{
		height: 100vh;
		position: relative;
	}
	.confirm{
		width: 650rpx;
		height: 88rpx;
		background-color: #3476F1;
		border-radius: 40rpx;
		text-align: center;
		line-height: 88rpx;
		color: #FFFFFF;
		font-size: 36rpx;
		font-weight: 500;
		margin: 0 auto;
		font-family: PingFang SC;
		position: absolute;
		bottom: 100rpx;
		left: 0rpx;
		right: 0rpx;
	}
</style>
